package com.bdqn.t320.ch13.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bdqn.t320.ch13.entity.User;
import com.bdqn.t320.ch13.entity.vo.UserVo;
import com.bdqn.t320.ch13.mapper.UserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImp extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    UserMapper userMapper;

    @Override
    public User getUserByUsrNameBiz(String usrName) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("usr_name", usrName);
        return userMapper.selectOne(queryWrapper);
    }

    @Override
    public List<String> getRightCodeByUserIdBiz(Long usrId) {
        return userMapper.getRightCodeByUserId(usrId);
    }

    @Override
    public IPage<User> getPageUserListBiz(Page<User> page, QueryWrapper wrapper) {
        return userMapper.selectPage(page, wrapper);
    }

    @Override
    public IPage<UserVo> getCustomPageUserListBiz(Page<UserVo> page, User user) {
        return userMapper.getCustomPageUserListDao(page, user);
    }

    @Override
    public boolean removeByIdBiz(Integer id) {
        return this.removeById(id);
    }

    @Override
    public User getUserByIdBiz(Integer id) {
        return this.getById(id);
    }

    @Override
    public int updateByIdBiz(User user) {
        return userMapper.updateById(user);
    }
}
